<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%archive_item}}`.
 */
class m220725_050920_create_archive_item_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('archive_item', [
            'id' => $this->primaryKey(),
            'id_section' => $this->integer()->notNull(),
            'title' => $this->string(255),
            'm_number' => $this->string(40),
            'is_Digitized' => $this->boolean()->defaultValue(0),
            'description' => $this->text(),
        ]);

        // creates index for column `id_section`
        $this->createIndex(
            'idx-archive_item-id_section',
            'archive_item',
            'id_section'
        );

        // add foreign key for table `archive_section`
        $this->addForeignKey(
            'fk-archive_item-id_section',
            'archive_item',
            'id_section',
            'archive_section',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `archive_section`
        $this->dropForeignKey(
            'fk-archive_item-id_section',
            'archive_item'
        );

        // drops index for column `id_section`
        $this->dropIndex(
            'idx-archive_item-id_section',
            'archive_item'
        );

        $this->dropTable('archive_item');
    }
}
